import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';


class OneBtnAlertDialog extends StatelessWidget {
  final String title;
  final String message;
  final String? btnName;
  final Function? onClick;

  const OneBtnAlertDialog({
    super.key,
    required this.title,
    required this.message,
    this.btnName = "确定",
    this.onClick,
  });

  @override
  Widget build(BuildContext context) {
    return CupertinoAlertDialog(
      title: Text(
        title,
        style: TextStyle(
          fontSize: 18.sp,
          color: Colors.black,
        ),
      ),
      content: Text(
        message,
        style: TextStyle(
          fontSize: 16.sp,
          color: Colors.black,
        ),
        textAlign: TextAlign.center,
      ),
      actions: <Widget>[
        CupertinoDialogAction(
          onPressed: () {
            Get.back();
            onClick?.call();
          },
          child: Text(
            btnName ?? '确定',
            style: TextStyle(
              fontSize: 16.sp,
              color: const Color(0xFF007AFF),
            ),
          ),
        ),
      ],
    );
  }
}

class TwoBtnAlertDialog extends StatelessWidget {
  final String title;
  final String message;
  final String? leftBtnName;
  final String? rightBtnName;
  final Function? onLeftClick;
  final Function? onRightClick;
  final bool autoPop;

  const TwoBtnAlertDialog({
    super.key,
    required this.title,
    required this.message,
    this.leftBtnName = "取消",
    this.rightBtnName = "确定",
    this.onLeftClick,
    this.onRightClick,
    this.autoPop = true,
  });

  @override
  Widget build(BuildContext context) {
    return CupertinoAlertDialog(
      title: Text(
        title,
        style: TextStyle(
          fontSize: 18.sp,
          color: Colors.black,
        ),
        textAlign: TextAlign.center,
      ),
      content: Text(
        message,
        style: TextStyle(
          fontSize: 16.sp,
          color: Colors.black,
        ),
      ),
      actions: <Widget>[
        CupertinoDialogAction(
          onPressed: () {
            if (autoPop)      Get.back();
            onLeftClick?.call();
          },
          child: Text(
            leftBtnName ?? '取消',
            style: TextStyle(
              fontSize: 16.sp,
              color: const Color(0xFF007AFF),
            ),
          ),
        ),
        CupertinoDialogAction(
          isDefaultAction: true,
          onPressed: () {
            if (autoPop)      Get.back();
            onRightClick?.call();
          },
          child: Text(
            rightBtnName ?? '确定',
            style: TextStyle(
              fontSize: 16.sp,
              color: const Color(0xFF007AFF),
            ),
          ),
        ),
      ],
    );
  }
}
